#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int MAXN = 5e5+10;
const db eps = 1e-7;

int n,h[MAXN],cnt,to[MAXN],ans;
db a[MAXN],f[MAXN];
struct edge{int v,nxt;}e[MAXN<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

void dfs(int x,int p,db s){
	f[x] = s + log(a[x]);
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue; dfs(y,x,s+log(to[x]-(p!=0)));
	}
}

int main (){
	n = in; for(int i = 1;i <= n;i++) a[i] = in;
	for(int i = 1;i < n;i++){int x = in,y = in;link(x,y);link(y,x);to[x]++;to[y]++;}
	dfs(1,0,log(1.0));
	sort(f+1,f+n+1); for(int i = 2,cnt = 1;i <= n+1;i++) if(i == n + 1 || f[i] - f[i-1] > eps) ans = max(ans,cnt),cnt = 1;else cnt++;
	printf("%d\n",n-ans);
	return 0;
}

